package com.tincher.twebutil

import android.os.CountDownTimer
import android.webkit.JavascriptInterface
import wendu.dsbridge.CompletionHandler

/**
 * author : hzq
 * e-mail : 380648100@qq.com
 * time   : 2020/04/17
 * desc   :
 */
class JsApii {
    @JavascriptInterface
    fun syn(msg: Any): Any {
        return msg
    }

    @JavascriptInterface
    fun asyn(
        msg: Any?,
        handler: CompletionHandler<Any?>
    ) {
        handler.complete(msg)
    }

    @JavascriptInterface
    fun callProgress(
        msg: Any?,
        handler: CompletionHandler<Any?>
    ) {
        object : CountDownTimer(11000, 1000) {
            var i=10
            override fun onTick(millisUntilFinished: Long) {
                handler.setProgressData(i--)
            }

            override fun onFinish() {
                //不写0会报错闪退
                handler.complete(0)
            }

        }.start()
    }
}